import 'package:baselib/utils/color_base_util.dart';
import 'package:baselib/utils/px_base_util.dart';
import 'package:baselib/utils/string_base_util.dart';
import 'package:baselib/utils/toast_util.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CommSelectGradientDialog extends Dialog {

  String negativeText;
  String positiveText;
  Function onCloseEvent;
  Function onPositivePressEvent;
  bool isTouchOutSideDissmiss;
  bool isTouchKeyBackDissmiss;

  List<String> datas;
  int initIndex;
  Function onSelectedItemChanged;

  CommSelectGradientDialog({
    Key key,
    @required this.datas,
    this.initIndex,
    this.negativeText,
    this.onSelectedItemChanged,
    this.positiveText,
    this.onPositivePressEvent,
    this.isTouchOutSideDissmiss = true,
    this.isTouchKeyBackDissmiss = true,
    @required this.onCloseEvent,
  }) : super(key: key){
    selectedIndex = (initIndex ?? 0);
  }
  int selectedIndex;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () {
        if (isTouchKeyBackDissmiss) {
          Navigator.of(context).pop();
        }
      },
      child: GestureDetector(
        onTap: () {
          if (isTouchOutSideDissmiss) {
            Navigator.of(context).pop();
          }
        },
        child: new Material(
          type: MaterialType.transparency,
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              GestureDetector(
                onTap: () {},
                child: GradientCardView(
                  elevation: PxBaseUtil().px_0,
                  margin: EdgeInsets.only(
                    left: PxBaseUtil().px_30,
                    right: PxBaseUtil().px_30,
                  ),
                  padding: EdgeInsets.only(),
                  borderRadius: BorderRadius.circular(PxBaseUtil().px_20),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(PxBaseUtil().px_20),
                      color: ColorBaseUtil().color_2F4072,
                    ),
                    padding: EdgeInsets.only(
                      left: PxBaseUtil().px_35,
                      right: PxBaseUtil().px_35,
                      top: PxBaseUtil().px_30,
                      bottom: PxBaseUtil().px_30,
                    ),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          child: Stack(
                            children: [
                              // Positioned(
                              //   bottom: PxBaseUtil().px_55,
                              //   child: Container(
                              //     height: PxBaseUtil().px_48,
                              //     width: PxBaseUtil().screenWidth,
                              //     decoration: BoxDecoration(
                              //       gradient: LinearGradient(
                              //         colors: [Color(0xffBF47FF), Color(0xff7602FD)],
                              //       ),
                              //       borderRadius: BorderRadius.circular(PxBaseUtil().px_30)
                              //     ),
                              //   ),
                              // ),
                              Container(
                                height: PxBaseUtil().px_164,
                                padding: EdgeInsets.all(PxBaseUtil().px_8),
                                child: CupertinoPicker(
                                  squeeze: 1,
                                  diameterRatio: 3,
                                  backgroundColor: Colors.transparent,
                                  itemExtent: PxBaseUtil().px_48,
                                  scrollController:
                                  FixedExtentScrollController(initialItem: initIndex),
                                  selectionOverlay: Container(
                                    height: PxBaseUtil().px_48,
                                    width: PxBaseUtil().screenWidth,
                                    decoration: BoxDecoration(
                                        gradient: LinearGradient(
                                          colors: [Color(0x60BF47FF), Color(0x607602FD)],
                                        ),
                                        borderRadius: BorderRadius.circular(PxBaseUtil().px_30)
                                    ),
                                  ),
                                  onSelectedItemChanged: (int selecedTempIndex){
                                    selectedIndex = selecedTempIndex;
                                    (onSelectedItemChanged==null)?((){}):onSelectedItemChanged(selectedIndex);
                                  },
                                  children: (datas ?? [])
                                      .map((e) => Container(
                                    height: PxBaseUtil().px_48,
                                    alignment: Alignment.center,
                                    child: Text(
                                      e,
                                      style: TextStyle(
                                        fontSize: PxBaseUtil().px_14,
                                        color: Colors.white,
                                      ),
                                    ),
                                  ))
                                      .toList(),
                                ),
                              )
                            ],
                          ),
                        ),
                        SizedBox(
                          height: PxBaseUtil().px_35,
                        ),
                        Container(
                          child: Row(
                            children: [
                              Expanded(
                                  child: GestureDetector(
                                onTap: () {
                                  if (onCloseEvent != null) onCloseEvent();
                                },
                                child: GradientCardView(
                                    elevation: PxBaseUtil().px_0,
                                    borderRadius: BorderRadius.circular(
                                        PxBaseUtil().px_18),
                                    child: Container(
                                      height: PxBaseUtil().px_35,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(
                                            PxBaseUtil().px_18),
                                        color:
                                            ColorBaseUtil().color_transparent,
                                      ),
                                      child: Center(
                                        child: Text(
                                          negativeText ??
                                              StringBaseUtil().Cancel,
                                          style: TextStyle(
                                              color:
                                                  ColorBaseUtil().color_white,
                                              fontSize: PxBaseUtil().px_14),
                                        ),
                                      ),
                                    )),
                              )),
                              SizedBox(
                                width: PxBaseUtil().px_30,
                              ),
                              Expanded(
                                  child: GestureDetector(
                                    onTap: () {
                                      if (onPositivePressEvent != null) onPositivePressEvent(selectedIndex);
                                    },
                                    child: GradientCardView(
                                        elevation: PxBaseUtil().px_0,
                                        borderRadius: BorderRadius.circular(
                                            PxBaseUtil().px_18),
                                        child: Container(
                                          height: PxBaseUtil().px_35,
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.circular(
                                                PxBaseUtil().px_18),
                                            color: ColorBaseUtil().color_2F4072,
                                          ),
                                          child: Center(
                                            child: Text(
                                              positiveText ??
                                                  StringBaseUtil().Confirm,
                                              style: TextStyle(
                                                  color: ColorBaseUtil()
                                                      .color_white,
                                                  fontSize: PxBaseUtil().px_14),
                                            ),
                                          ),
                                        )),
                                  )
                              ),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
